#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;


 // Definition for a binary tree node.
  struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  };
 
class Solution {
public:
    bool isSymmetric(TreeNode* root) {
        if(root==NULL){
            return true;
        }       
        return func(root->left,root->right);
        
    }
    bool func(TreeNode* rootLeft, TreeNode* rootRight){
        if(rootLeft==NULL&&rootRight==NULL){
            return true;
        }
        if(rootLeft!=NULL&&rootRight!=NULL&&rootLeft->val==rootRight->val){
            bool Left = func(rootLeft->left,rootRight->right);
            bool Right = func(rootLeft->right,rootRight->left);
            return Left&&Right;
        }
        else{
            return false;
        }  
    }
};

int main(){
    TreeNode* head= new TreeNode(1);
    head->left = new TreeNode(2);
    head->right = new TreeNode(2);
    head->left->left = new TreeNode(3);
    head->left->right = new TreeNode(4);
    head->right->left = new TreeNode(4);
    head->right->right = new TreeNode(3);
    Solution S;
    cout<<S.isSymmetric(head)<<endl;
}
